package org.firestorm.traficforecast.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class FileUtils {

	public static void main(String[] args) {
		File inputFile = new File("E:\\HOC TAP\\KI 20141\\Project\\WorkSpace\\input.txt");
		double[][] input = readFromFile(inputFile);
		System.out.println(input.length);
	}
	public static double[][] readFromFile(File input){
		FileReader reader = null;
		try {
			reader = new FileReader(input);
			ArrayList<double[]> list = new ArrayList<double[]>();
			BufferedReader br = null;
			try {
				br = new BufferedReader(reader);
				String line = br.readLine();
				while(line != null){
					String[] lines = line.split(", ");
					double[] tmp = new double[8];
					for(int i = 0; i < 8; i++){
						tmp[i] = Double.parseDouble(lines[i]);
					}
					list.add(tmp);
					line = br.readLine();
				}
				double[][] result = new double[list.size()][8];
				list.toArray(result);
				return result;
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				return null;
			} catch (IOException e) {
				e.printStackTrace();
				return null;
			} finally{
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		} finally{
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
}
